/**
 * 所有建筑类型
 */
export const AllStructureTypes: StructureConstant[] = [
    STRUCTURE_EXTENSION,
    STRUCTURE_RAMPART,
    STRUCTURE_ROAD,
    STRUCTURE_SPAWN,
    STRUCTURE_LINK,
    STRUCTURE_WALL,
    STRUCTURE_STORAGE,
    STRUCTURE_TOWER,
    STRUCTURE_OBSERVER,
    STRUCTURE_POWER_SPAWN,
    STRUCTURE_EXTRACTOR,
    STRUCTURE_LAB,
    STRUCTURE_TERMINAL,
    STRUCTURE_CONTAINER,
    STRUCTURE_NUKER,
    STRUCTURE_FACTORY,
    STRUCTURE_KEEPER_LAIR,
    STRUCTURE_CONTROLLER,
    STRUCTURE_POWER_BANK,
    STRUCTURE_PORTAL,
    STRUCTURE_INVADER_CORE,
]

/**
 * 可以建造的建筑类型
 */
export const BuildableStructureTypes: BuildableStructureConstant[] = [
    // link 优先，因为挖矿需要 link
    STRUCTURE_LINK,
    STRUCTURE_SPAWN,
    STRUCTURE_TERMINAL,
    STRUCTURE_EXTENSION,
    STRUCTURE_STORAGE,
    STRUCTURE_RAMPART,
    STRUCTURE_TOWER,
    STRUCTURE_LAB,
    STRUCTURE_CONTAINER,

    STRUCTURE_ROAD,

    STRUCTURE_OBSERVER,
    STRUCTURE_POWER_SPAWN,
    STRUCTURE_EXTRACTOR,
    STRUCTURE_FACTORY,
    STRUCTURE_NUKER,
    STRUCTURE_WALL,
]

/**
 * 可以建造的建筑类型（低级房）
 */
export const LowBuildableStructureTypes: BuildableStructureConstant[] = [
    // 优先路，保障物流
    STRUCTURE_ROAD,

    STRUCTURE_LINK,
    STRUCTURE_SPAWN,
    STRUCTURE_TERMINAL,
    STRUCTURE_EXTENSION,
    STRUCTURE_STORAGE,
    STRUCTURE_RAMPART,
    STRUCTURE_TOWER,
    STRUCTURE_LAB,
    STRUCTURE_CONTAINER,

    STRUCTURE_OBSERVER,
    STRUCTURE_POWER_SPAWN,
    STRUCTURE_EXTRACTOR,
    STRUCTURE_FACTORY,
    STRUCTURE_NUKER,
    STRUCTURE_WALL,
]

/**
 * 不可建造的建筑类型
 */
export const UnbuildableStructureTypes: Exclude<StructureConstant, BuildableStructureConstant>[] = [
    STRUCTURE_KEEPER_LAIR,
    STRUCTURE_CONTROLLER,
    STRUCTURE_POWER_BANK,
    STRUCTURE_PORTAL,
    STRUCTURE_INVADER_CORE,
]

/**
 * 可以行走的建筑类型
 */
export const WalkableStructureTypes: StructureConstant[] = [STRUCTURE_ROAD, STRUCTURE_CONTAINER, STRUCTURE_RAMPART]

/**
 * 重要建筑
 */
export const ImportantStructureTypes: StructureConstant[] = [
    STRUCTURE_TOWER,
    STRUCTURE_SPAWN,
    STRUCTURE_TERMINAL,
    STRUCTURE_LAB,
    STRUCTURE_STORAGE,
    STRUCTURE_EXTENSION,
    STRUCTURE_RAMPART,
    STRUCTURE_WALL,
    STRUCTURE_POWER_SPAWN,
    STRUCTURE_NUKER,
    STRUCTURE_FACTORY,
    STRUCTURE_OBSERVER,
]

/**
 * 不重要建筑
 */
export const UnimportantStructureTypes: StructureConstant[] = [
    STRUCTURE_ROAD,
    STRUCTURE_LINK,
    STRUCTURE_EXTRACTOR,
    STRUCTURE_CONTAINER,
]

/**
 * 防核建筑
 */
export const NukeDefendStructureTypes: StructureConstant[] = [
    STRUCTURE_SPAWN,
    STRUCTURE_TERMINAL,
    STRUCTURE_LAB,
    STRUCTURE_STORAGE,
    STRUCTURE_POWER_SPAWN,
    STRUCTURE_NUKER,
    STRUCTURE_FACTORY,
]

/**
 * 单个建筑类型，该类型建筑房间内只有1个
 */
export const SingleStructureTypes: StructureConstant[] = [
    STRUCTURE_TERMINAL,
    STRUCTURE_POWER_SPAWN,
    STRUCTURE_NUKER,
    STRUCTURE_FACTORY,
    STRUCTURE_OBSERVER,
    STRUCTURE_STORAGE,
    STRUCTURE_EXTRACTOR,
    STRUCTURE_CONTROLLER,
]

/**
 * 不同等级房间的最大扩展能量
 */
export const CONTROLLER_ENERGY = {
    1: 300,
    2: 550,
    3: 800,
    4: 1300,
    5: 1800,
    6: 2300,
    7: 5600,
    8: 12900,
} as const

/**
 * 从反应目标产物获取其底物的对应表
 */
export const reactionSource = {
    // 三级化合物
    [RESOURCE_CATALYZED_GHODIUM_ACID]: [RESOURCE_GHODIUM_ACID, RESOURCE_CATALYST],
    [RESOURCE_CATALYZED_GHODIUM_ALKALIDE]: [RESOURCE_GHODIUM_ALKALIDE, RESOURCE_CATALYST],
    [RESOURCE_CATALYZED_KEANIUM_ACID]: [RESOURCE_KEANIUM_ACID, RESOURCE_CATALYST],
    [RESOURCE_CATALYZED_KEANIUM_ALKALIDE]: [RESOURCE_KEANIUM_ALKALIDE, RESOURCE_CATALYST],
    [RESOURCE_CATALYZED_LEMERGIUM_ACID]: [RESOURCE_LEMERGIUM_ACID, RESOURCE_CATALYST],
    [RESOURCE_CATALYZED_LEMERGIUM_ALKALIDE]: [RESOURCE_LEMERGIUM_ALKALIDE, RESOURCE_CATALYST],
    [RESOURCE_CATALYZED_UTRIUM_ACID]: [RESOURCE_UTRIUM_ACID, RESOURCE_CATALYST],
    [RESOURCE_CATALYZED_UTRIUM_ALKALIDE]: [RESOURCE_UTRIUM_ALKALIDE, RESOURCE_CATALYST],
    [RESOURCE_CATALYZED_ZYNTHIUM_ACID]: [RESOURCE_ZYNTHIUM_ACID, RESOURCE_CATALYST],
    [RESOURCE_CATALYZED_ZYNTHIUM_ALKALIDE]: [RESOURCE_ZYNTHIUM_ALKALIDE, RESOURCE_CATALYST],
    // 二级化合物
    [RESOURCE_GHODIUM_ACID]: [RESOURCE_GHODIUM_HYDRIDE, RESOURCE_HYDROXIDE],
    [RESOURCE_GHODIUM_ALKALIDE]: [RESOURCE_GHODIUM_OXIDE, RESOURCE_HYDROXIDE],
    [RESOURCE_KEANIUM_ACID]: [RESOURCE_KEANIUM_HYDRIDE, RESOURCE_HYDROXIDE],
    [RESOURCE_KEANIUM_ALKALIDE]: [RESOURCE_KEANIUM_OXIDE, RESOURCE_HYDROXIDE],
    [RESOURCE_LEMERGIUM_ACID]: [RESOURCE_LEMERGIUM_HYDRIDE, RESOURCE_HYDROXIDE],
    [RESOURCE_LEMERGIUM_ALKALIDE]: [RESOURCE_LEMERGIUM_OXIDE, RESOURCE_HYDROXIDE],
    [RESOURCE_UTRIUM_ACID]: [RESOURCE_UTRIUM_HYDRIDE, RESOURCE_HYDROXIDE],
    [RESOURCE_UTRIUM_ALKALIDE]: [RESOURCE_UTRIUM_OXIDE, RESOURCE_HYDROXIDE],
    [RESOURCE_ZYNTHIUM_ACID]: [RESOURCE_ZYNTHIUM_HYDRIDE, RESOURCE_HYDROXIDE],
    [RESOURCE_ZYNTHIUM_ALKALIDE]: [RESOURCE_ZYNTHIUM_OXIDE, RESOURCE_HYDROXIDE],
    // 一级化合物
    [RESOURCE_GHODIUM_HYDRIDE]: [RESOURCE_GHODIUM, RESOURCE_HYDROGEN],
    [RESOURCE_GHODIUM_OXIDE]: [RESOURCE_GHODIUM, RESOURCE_OXYGEN],
    [RESOURCE_KEANIUM_HYDRIDE]: [RESOURCE_KEANIUM, RESOURCE_HYDROGEN],
    [RESOURCE_KEANIUM_OXIDE]: [RESOURCE_KEANIUM, RESOURCE_OXYGEN],
    [RESOURCE_LEMERGIUM_HYDRIDE]: [RESOURCE_LEMERGIUM, RESOURCE_HYDROGEN],
    [RESOURCE_LEMERGIUM_OXIDE]: [RESOURCE_LEMERGIUM, RESOURCE_OXYGEN],
    [RESOURCE_UTRIUM_HYDRIDE]: [RESOURCE_UTRIUM, RESOURCE_HYDROGEN],
    [RESOURCE_UTRIUM_OXIDE]: [RESOURCE_UTRIUM, RESOURCE_OXYGEN],
    [RESOURCE_ZYNTHIUM_HYDRIDE]: [RESOURCE_ZYNTHIUM, RESOURCE_HYDROGEN],
    [RESOURCE_ZYNTHIUM_OXIDE]: [RESOURCE_ZYNTHIUM, RESOURCE_OXYGEN],
    [RESOURCE_GHODIUM]: [RESOURCE_ZYNTHIUM_KEANITE, RESOURCE_UTRIUM_LEMERGITE],
    // 基础化合物
    [RESOURCE_ZYNTHIUM_KEANITE]: [RESOURCE_ZYNTHIUM, RESOURCE_KEANIUM],
    [RESOURCE_UTRIUM_LEMERGITE]: [RESOURCE_UTRIUM, RESOURCE_LEMERGIUM],
    [RESOURCE_HYDROXIDE]: [RESOURCE_HYDROGEN, RESOURCE_OXYGEN],
}

/**
 * bar 压缩对应表
 */
export const zipMap = {
    energy: RESOURCE_BATTERY,
    L: 'lemergium_bar',
    Z: 'zynthium_bar',
    K: 'keanium_bar',
    U: 'utrium_bar',
    G: 'ghodium_melt',
    O: 'oxidant',
    H: 'reductant',
    X: 'purifier',
} as const

/**
 * bar 解压对应表
 */
export const unzipMap = {
    battery: RESOURCE_ENERGY,
    lemergium_bar: RESOURCE_LEMERGIUM,
    zynthium_bar: RESOURCE_ZYNTHIUM,
    keanium_bar: RESOURCE_KEANIUM,
    utrium_bar: RESOURCE_UTRIUM,
    ghodium_melt: RESOURCE_GHODIUM,
    oxidant: RESOURCE_OXYGEN,
    reductant: RESOURCE_HYDROGEN,
    purifier: RESOURCE_CATALYST,
} as const

/**
 * boost 资源到 body 部件的映射表
 */
export const ResourcePartMap: { [type in MineralBoostConstant]: BodyPartConstant } = {
    UH: 'attack',
    UH2O: 'attack',
    XUH2O: 'attack',
    UO: 'work',
    UHO2: 'work',
    XUHO2: 'work',
    KH: 'carry',
    KH2O: 'carry',
    XKH2O: 'carry',
    KO: 'ranged_attack',
    KHO2: 'ranged_attack',
    XKHO2: 'ranged_attack',
    LH: 'work',
    LH2O: 'work',
    XLH2O: 'work',
    LO: 'heal',
    LHO2: 'heal',
    XLHO2: 'heal',
    ZH: 'work',
    ZH2O: 'work',
    XZH2O: 'work',
    ZO: 'move',
    ZHO2: 'move',
    XZHO2: 'move',
    GH: 'work',
    GH2O: 'work',
    XGH2O: 'work',
    GO: 'tough',
    GHO2: 'tough',
    XGHO2: 'tough',
}

/**
 * 一级化合物
 */
export const t1 = ['UH', 'UO', 'KH', 'KO', 'LH', 'LO', 'ZH', 'ZO', 'GH', 'GO'] as MineralBoostConstant[]

/**
 * 二级化合物
 */
export const t2 = [
    'UH2O',
    'UHO2',
    'KH2O',
    'KHO2',
    'LH2O',
    'LHO2',
    'ZH2O',
    'ZHO2',
    'GH2O',
    'GHO2',
] as MineralBoostConstant[]

/**
 * 三级化合物
 */
export const t3 = [
    'XUH2O',
    'XUHO2',
    'XKH2O',
    'XKHO2',
    'XLH2O',
    'XLHO2',
    'XZH2O',
    'XZHO2',
    'XGH2O',
    'XGHO2',
] as MineralBoostConstant[]

/**
 * 部件到 t1 的映射表
 */
export const partTot1: { [part in BodyPartConstant]?: MineralBoostConstant } = {
    attack: 'UH',
    carry: 'KH',
    heal: 'LO',
    move: 'ZO',
    ranged_attack: 'KO',
    tough: 'GO',
    work: 'ZH',
}

/**
 * 部件到 t2 的映射表
 */
export const partTot2: { [part in BodyPartConstant]?: MineralBoostConstant } = {
    attack: 'UH2O',
    carry: 'KH2O',
    heal: 'LHO2',
    move: 'ZHO2',
    ranged_attack: 'KHO2',
    tough: 'GHO2',
    work: 'ZH2O',
}

/**
 * 部件到 t3 的映射表
 */
export const partTot3: { [part in BodyPartConstant]?: MineralBoostConstant } = {
    attack: 'XUH2O',
    carry: 'XKH2O',
    heal: 'XLHO2',
    move: 'XZHO2',
    ranged_attack: 'XKHO2',
    tough: 'XGHO2',
    work: 'XZH2O',
}

/**
 * boost 等级映射表
 */
export const boostLevelMap = {
    t1: t1,
    t2: t2,
    t3: t3,
}

/**
 * 不同等级对应的部件 boost 映射表
 */
export const levelBoostMap = {
    t1: partTot1,
    t2: partTot2,
    t3: partTot3,
}
